<?php
include("../common.inc.php");
InitGP(array("page","action","cid","delids")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include_once(INC_PATH."/city.class.php");
$city=new CityClass();


if(empty($action)){
	//获取当前页码
	$total=$city->getcount(); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$city->getdata("$offset,$pagesize"); //获取团购数据
	
	//包含后台模板文件
	include("tpl/city_manage.htm");
}elseif ($action=="add") {
	InitGP(array("cityname","default","Submit")); //初始化变量全局返回
	if(!empty($Submit) && !empty($cityname)){
		$def=$default?1:0;
		if ($def==1) {
			//清除其他默认地区
			editstate("city","def","1",0);
		}
		$city->add(Char_cv($cityname),$def);
		showmsg("添加成功!","city_manage.php");//成功
	}else {
		include("tpl/city_manage.htm");
	}
}elseif ($action=="edit") {
	InitGP(array("cid","cityname","Submit")); //初始化变量全局返回
	if(!empty($Submit)){
		//处理提交动作
		if(isset($cid) && isset($cityname)){
		//执行编辑操作
		$info=$city->edit($cid,$cityname);
			if($info=="OK"){
				showmsg("编辑成功!","city_manage.php");//成功
			}else showmsg($info,"-1");//出错！
		}else showmsg("缺少参数","-1");//出错！
		
	}else {
	
	//编辑信息表单
	$dataedit=$city->getdata(1,"cid={$cid}");
	$value=$dataedit[0];//获取第一条记录
	//包含后台模板文件
	include("tpl/city_manage.htm");	
	}
}elseif ($action=="lose") {
	InitGP(array("cid")); //初始化变量全局返回
	editstate("city","state","cid='{$cid}'",0);
	showmsg("设置失效状态成功!","city_manage.php");//成功
}elseif ($action=="check") {
	InitGP(array("cid")); //初始化变量全局返回
	editstate("city","state","cid='{$cid}'",1);
	showmsg("恢复状态成功!","city_manage.php");//成功
}elseif ($action=="setdef") {
	InitGP(array("cid")); //初始化变量全局返回
	editstate("city","def","1",0);
	editstate("city","def","cid='{$cid}'",1);
	showmsg("设置默认成功!","city_manage.php");//成功
}elseif ($action=="cleardef") {
	InitGP(array("cid")); //初始化变量全局返回
	editstate("city","def","cid='{$cid}'",0);
	showmsg("取消默认成功!","city_manage.php");//成功

	
}elseif ($action=="del" && !empty($cid)){
	//执行删除操作
	$cid=GetNum($cid);
	$info=$city->del($cid);
	if($info=="OK")showmsg("删除成功！","city_manage.php");
	else showmsg($info,"article_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","city_manage.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$city->del($id);
	}
	if($info=="OK")showmsg("删除成功！","city_manage.php");
	else showmsg($info,"city_manage.php");
}


?>

